//
//  PushNative.m
//  rn
//
//  Created by 牛冬冬 on 2018/3/28.
//  Copyright © 2018年 Jevons-niu. All rights reserved.
//

#import "PushNative.h"
#import "AppManager.h"
#import "AppDelegate.h"
#import "OtherViewController.h"

@interface PushNative ()<RCTBridgeModule>

@end

@implementation PushNative

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(RNPushVC:(NSDictionary *)dic){
    
    logd(@"RN传入原生界面的数据为:%@",dic);
    
    if (dic) {
        //主要这里必须使用主线程发送,不然有可能失效
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if ([dic.allKeys containsObject:@"moduleId"]) {
                
                if ([dic[@"moduleId"] integerValue] >= 20000) {
                    
                    if ([dic[@"moduleId"] integerValue] == 20001) {
                       
                        OtherViewController *vc = [[OtherViewController alloc] init];
                        vc.moduleId = dic[@"moduleId"];
                        
                        if ([dic.allKeys containsObject:@"title"]) {
                            vc.title = dic[@"title"];
                        }
                        
                        [[[Helper share] currentNavigationController] pushViewController:vc animated:YES];
                    }else {
                        
                        if ([dic.allKeys containsObject:@"viewController"]) {
                            UIViewController *vc = [[NSClassFromString(dic[@"viewController"]) alloc] init];
                            [[[Helper share] currentNavigationController] pushViewController:vc animated:YES];
                        }
                    }
                }else {
                    
                    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
                    [AppManager removeShare];
                    [delegate.window setRootViewController:[AppManager share].tabBarController];
                }
            }
        });
    }
}

@end
